<script type="text/javascript">

var paginationTotal = 2;//记录总数
$(function(){
//	initData(0); //初始化分页<{$lang.data}>
	clear();
	$("#add").dialog({
		autoOpen:false,
		modal:true,
		width:380,
		show:"slide",
		buttons: {
			'<{$lang.ok}>': function() {
				save();
			},
	    	'<{$lang.cancel}>': function() {
				$(this).dialog('close');
			 }
		}
	});
	
	$("#right_confirm").dialog({
		autoOpen:false,
		modal:true,
		height:160,
		show:"slide",
		buttons: {
			'<{$lang.ok}>': function() {
				loading();
				$.ajax({
					type: "post",
					async: false,
					dataType: "json",
					url: "/user/menu/delete", 
					data: "id=" + Uid,
					success: function(json) { 
						if(json.ask=='1'){
							initData(0);
							messags="<{$lang.success}><{$lang.delete}>！";
						}else{
							messags="<{$lang.delete}><{$lang.fail}>！";
						}
						$("#message").html(messags);
					}
				});
				closeLoading();
				$(this).dialog('close');
			},
	    	'<{$lang.cancel}>': function() {
					$(this).dialog('close');
			 }
		}

	});
	
});

function loadData(page,pageSize){
	var um_title = $('[name=menu_title]').val();
	loading();
	$.ajax({ //这里使用到Jquery的ajax<{$lang.method}>
		type: "POST",
		async: false,
		dataType: "json",
		url: "/user/menu/list", //请求的处理url
		data:{
			'page':page,
			'pageSize':pageSize,
			'um_title':um_title
		},
		success: function(json) {
			var list = '';
			paginationTotal=json.total;
			if(json.ask != 1){
				list = "<td colspan='9' class=''>&nbsp;<{$lang.no_data}></td>";
			}else {
				$.each(json.result, function(key, val){				
					list += "<tr>";					
					list += "<td>"+val.um_id+"</td>";					
					list += "<td>"+val.um_title+"</td>";				
					list += "<td>"+val.um_en_title+"</td>";
					list += "<td>"+val.um_url+"</td>";
					list += "<td>"+val.um_sort+"</td>";
					list += "<td style='display:none;'>"+val.um_css+"</td>";
					list += "<td>"+val.um_color+"</td>";					
					
					list += "<td><a href=\"javascript:editMenu("+val.um_id+");\"><img title='<{$lang.update}>' src='/images/icon/edit.gif'></a></td>";
					list += "<td><a href=\"javascript:editSub("+val.um_id+",'edit');\" ><img title='<{$lang.sub_menu}>' src='/images/icon/authority.png'></a></td>";
					list += "<td><a href=\"javascript:delelteInfo("+val.um_id+")\"><img title='<{$lang.delete}>' src='/images/icon/delete.gif'></a></td>";
					
					list += "</tr>";
				});
				closeLoading();
			}
			$("#list").html(list);
		}
	}); 
}

function editAction(id,act){
	 openIframeDialog('/user/right/actions/urid/'+id,680,550)
}

function search(){	
	initData(0);
}

function editMenu(id){
	clear();
	if(id){
		$.ajax({
			type: "POST",
			async: false,
			dataType: "json",
			url: "/user/menu/single", //请求的处理url
			data:{'id':id},
			success: function(json) {
				if(json.ask == 1 ) {
					var val = json.result;
					$('[name=um_id]').val(val.um_id);
					$('[name=um_title]').val(val.um_title);
					$('[name=um_en_title]').val(val.um_en_title);
					$('[name=um_url]').val(val.um_url);
					$('[name=um_css]').val(val.um_css);
					$('[name=um_sort]').val(val.um_sort);
				}
				$("#add").dialog("open");
			}
		});
	}else{		
		$("#add").dialog("open");
	}
}

function save(){
	vForm='';
	vForm = $("#createForm").serializeArray();
	var tip = '';
	$.ajax({
		type: "POST",
		async: false,
		dataType: "json",
		url: "/user/menu/edit", //请求的处理url
		data:vForm,
		success: function(json) {
			if(json.ask){
				tip = '<{$lang.operation}><{$lang.success}>';					
			}else{
				tip = '<{$lang.operation}><{$lang.fail}>';	
			}
//			initData(0);
			loadData(paginationCurrentPage,paginationPageSize);
			$("#add").dialog("close");
			$('#message').text(tip);
		}
	});
}

//<{$lang.delete}>
function delelteInfo(id){
	if(id==''||id==undefined){
		return false;
	}
	Uid = id;
	$('#right_confirm').dialog('open');
}

function clear(){
	$('[name=um_id]').val('');
	$('[name=menu_title]').val('');		//必须<{$lang.clear}>，否则会报错
	$('[name=um_title]').val('');
	
	$('[name=um_url]').val('');
	$('[name=um_css]').val('');
	$('[name=um_sort]').val('');
}
</script>
<style type="text/css">
.button{background:url(images/left-menu-li.gif) repeat-x left top #F1F6F9; border:1px solid #318DAC; font-weight:bold; padding:2px 5px; font-weight:lighter; color:#318DAC; vertical-align:middle; -moz-border-radius:3px; -webkit-border-radius:3px; margin:auto 5px}
</style>

<div id="right_confirm" style="display: none;">
	<p style="text-align:center;font-size: 14px;color: red;font-weight: bold;">
	<{$lang.delete_sure}>？
	</p>
</div>

<div id="iTitle">
	<div id="iTitleSub">
	
		<form id="sForm" name="sForm" onkeypress="if(event.keyCode==13){return false;}">
		<div>
		<label>
			<{$lang.title}>:<input id="menu_title" class="myInput" type="text" onkeyup="if(event.keyCode==13){search();}" name="menu_title">
		</label>&nbsp;
		<input class="button" type="button" value="<{$lang.search}>" onclick="search();">&nbsp;
		<input class="button" type="button" value="<{$lang.add}>"  id="addButton" onclick="editMenu('')">
		</div>
		</form>
		
	</div>
	<div id="message" style="color:red;"></div>
	<div class="myClear"></div>
</div><!-- id="iTitle" 结束 -->

<h3><{$lang.nemu}><{$lang.list}></h3>

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="myTab">	
	<thead><tr>
    	<th>ID</th>
    	<th><{$lang.title}></th>
    	<th><{$lang.en_title}></th>
   		<th>URL</th>
    	<th><{$lang.sort}></th>
        <th style='display:none;'>CSS</th>
        <th><{$lang.color}></th>
        <th><{$lang.update}></th>
        <th><{$lang.sub_menu}></th>
        <th><{$lang.delete}></th>            
	</tr></thead>
    
	<tbody id="list"></tbody>
	
</table>

<div class="pagination"></div>

<style type="text/css">
div#add{
	text-align:center;
}
div.info{
	text-align:left;
}
div.item{
	margin-bottom: 12px;
}
input.text {
    height: 22px;    
    margin-left: 8px;
}
span.text{
	margin-left: 8px;
}
</style>

<div id="add" title="<{$lang.nemu}><{$lang.edit}>" style="display:none;">
 
	<div class="info">
		<div class="validateTips" id="tips"></div>
		
		<form id="createForm" name="createForm" >
		
		<div class="item">
			<span class="userInfoLeft"><{$lang.title}>:</span>
			<span class="userInfoRight">
				<input type="hidden" name="um_id" id="um_id" />
				<input type="text" name="um_title" id="um_title" class="text ui-widget-content ui-corner-all"/>
			</span>
			<div style="clear:both;"></div>
		</div>
		<div class="item">
			<span class="userInfoLeft"><{$lang.en_title}>:</span>
			<span class="userInfoRight">
				<input type="text" name="um_en_title" id="um_en_title" class="text ui-widget-content ui-corner-all"/>
			</span>
			<div style="clear:both;"></div>
		</div>
		<div class="item">
			<span class="userInfoLeft">URL:</span>
			<span class="userInfoRight">
				<input type="text" name="um_url" id="um_url" class="text ui-widget-content ui-corner-all"/>
			</span>
			<div style="clear: both;"></div>
		</div>				
			           
		<div class="item" style='display:none;'>
			<span class="userInfoLeft">CSS:</span>
			<span class="text userInfoRight">
				<select name="um_css" id="um_css" class="ui-widget-content ui-corner-all" >
					<option value="blue">蓝色</option>
					<option value="green">绿色</option>
					<option value="red">红色</option>
				</select>				
			</span>
			<div style="clear: both;"></div>
		</div>
		
		<div class="item">
			<span class="userInfoLeft"><{$lang.sort}>:</span>
			<span class="userInfoRight">
				<input type="text" name="um_sort" id="um_sort" class="text ui-widget-content ui-corner-all"/>
			</span>
			<div style="clear: both;"></div>
		</div>
		
		</form>
	
	</div>
</div>